package pl.perseus.service.classes;

import java.util.List;

import lombok.Data;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pl.perseus.dao.IClassesDao;
import pl.perseus.model.Account;
import pl.perseus.model.Classes;
import pl.perseus.model.User;
import pl.perseus.service.account.IAccountService;
import pl.perseus.service.user.IUserService;

@Data
@Service
@Transactional
public class ClassesService implements IClassesService{

	@Autowired
	IUserService userService;
	
	@Autowired
	IAccountService accountService;
	
	@Autowired
	private IClassesDao classesDao;
	
	@Override
	public Classes insertClasses(Classes c) {
		return classesDao.insertClasses(c);
	}
	
	@Override
	public Classes selectByIdClasses(Long id){
		return classesDao.selectByIdClasses(id);
	}

	@Override
	public List<Classes> getAllClasses(){
		return classesDao.getAllClasses();
	}

	@Override
	public List<Classes> getClassesForTeacher(User user) {
		return classesDao.getClassesForTeacher(user);
	}
	
	@Override
	public List<Classes> getClassesForUser(String login){
		User user = userService.selectUserByLogin(login);
		Account account = accountService.getAccountForUser(user);
		if(accountService.isAdmin(account))
			return getAllClasses();
		
		if(accountService.isTeacher(account))
			return getClassesForTeacher(user);
			
		return null;
	}
	
}
